// pages/dingdan/dingdan.js
import {
  request
} from "../../pages/request2/request2";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orders: [{
        "order_id": 428,
        "user_id": 23,
        "order_number": "HMDD20190802000000000428",
        "order_price": 13999,
        "order_pay": "0",
        "is_send": "否",
        "trade_no": "",
        "order_fapiao_title": "个人",
        "order_fapiao_company": "",
        "order_fapiao_content": "",
        "consignee_addr": "广东省广州市海珠区新港中路397号",
        "pay_status": "1",
        "create_time": 1681121111,
        "update_time": 1564731518,
        "order_detail": null,
        "goods": [{
          "id": 717,
          "order_id": 428,
          "goods_id": 43986,
          "goods_price": 13999,
          "goods_number": 1,
          "goods_total_price": 13999,
          "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
          "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
        }],
        "total_count": 1,
        "total_price": 13999
      },
      {
        "order_id": 429,
        "user_id": 23,
        "order_number": "HMDD20190802000000000428",
        "order_price": 13999,
        "order_pay": "0",
        "is_send": "否",
        "trade_no": "",
        "order_fapiao_title": "个人",
        "order_fapiao_company": "",
        "order_fapiao_content": "",
        "consignee_addr": "广东省广州市海珠区新港中路397号",
        "pay_status": "1",
        "create_time": 1681121111,
        "update_time": 1564731518,
        "order_detail": null,
        "goods": [{
          "id": 717,
          "order_id": 428,
          "goods_id": 43986,
          "goods_price": 13999,
          "goods_number": 1,
          "goods_total_price": 13999,
          "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
          "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
        }],
        "total_count": 1,
        "total_price": 13999
      },
      {
        "order_id": 430,
        "user_id": 23,
        "order_number": "HMDD20190802000000000428",
        "order_price": 13999,
        "order_pay": "0",
        "is_send": "否",
        "trade_no": "",
        "order_fapiao_title": "个人",
        "order_fapiao_company": "",
        "order_fapiao_content": "",
        "consignee_addr": "广东省广州市海珠区新港中路397号",
        "pay_status": "1",
        "create_time": 1681121111,
        "update_time": 1564731518,
        "order_detail": null,
        "goods": [{
          "id": 717,
          "order_id": 428,
          "goods_id": 43986,
          "goods_price": 13999,
          "goods_number": 1,
          "goods_total_price": 13999,
          "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
          "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
        }],
        "total_count": 1,
        "total_price": 13999
      },
      {
        "order_id": 431,
        "user_id": 23,
        "order_number": "HMDD20190802000000000428",
        "order_price": 13999,
        "order_pay": "0",
        "is_send": "否",
        "trade_no": "",
        "order_fapiao_title": "个人",
        "order_fapiao_company": "",
        "order_fapiao_content": "",
        "consignee_addr": "广东省广州市海珠区新港中路397号",
        "pay_status": "1",
        "create_time": 1681121111,
        "update_time": 1564731518,
        "order_detail": null,
        "goods": [{
          "id": 717,
          "order_id": 428,
          "goods_id": 43986,
          "goods_price": 13999,
          "goods_number": 1,
          "goods_total_price": 13999,
          "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
          "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
        }],
        "total_count": 1,
        "total_price": 13999
      },
      {
        "order_id": 432,
        "user_id": 23,
        "order_number": "HMDD20190802000000000428",
        "order_price": 13999,
        "order_pay": "0",
        "is_send": "否",
        "trade_no": "",
        "order_fapiao_title": "个人",
        "order_fapiao_company": "",
        "order_fapiao_content": "",
        "consignee_addr": "广东省广州市海珠区新港中路397号",
        "pay_status": "1",
        "create_time": 1681121111,
        "update_time": 1564731518,
        "order_detail": null,
        "goods": [{
          "id": 717,
          "order_id": 428,
          "goods_id": 43986,
          "goods_price": 13999,
          "goods_number": 1,
          "goods_total_price": 13999,
          "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
          "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
        }],
        "total_count": 1,
        "total_price": 13999
      }
    ],
    tabs: [{
        id: 0,
        value: "全部",
        isActive: true
      },
      {
        id: 1,
        value: "代付款",
        isActive: false
      },
      {
        id: 2,
        value: "待发货",
        isActive: false
      },
      {
        id: 3,
        value: "退款/退货",
        isActive: false
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let tabs = this.data.tabs
    // index数组的下标
    tabs.forEach((item, index) => {
      if (index == options.type) {
        item.isActive = true
      } else {
        item.isActive = false
      }
    })
    this.setData({
      tabs
    })
    //必须是企业号 才能拿到token 没授权就没有数据 所以用了死的数据
    const token = wx.getStorageSync("token");
    let header = "值"
    console.log(token);
    const res = await request({
      url: "/my/orders/all",
      data: 1,
      header
    })
    this.getorders()

  },
  getorders() {
    let orders = this.data.orders.map((item) => {
      item.create_time = new Date(item.create_time * 1000).toLocaleString()
      return item
    })
    this.setData({
      orders
    })
    console.log(this.data.orders);
  },
  tabsChange(e) {
    wx.showLoading({
      title: "加载中",
    });
    let index = e.detail.a.index
    let tabs = this.data.tabs
    //  tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false); 简易代码
    tabs.forEach((item, id) => {
      if (id == index) {
        item.isActive = true
      } else {
        item.isActive = false
      }
    })
    this.setData({
      tabs
    })
    let ding = setTimeout(function () {
      wx.hideLoading()
    }, 500)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})